package ${controllerPackagePath};

import com.alibaba.fastjson.JSON;
import ${boPackagePath}.${entityName?cap_first}Bo;
import ${searchBoPackagePath}.${entityName?cap_first}SearchBo;
import ${servicePackagePath}.${entityName?cap_first}Service;
import ${innerTransferUtilPackagePath}.InnerTransferUtil;
import ${searchVoPackagePath}.${entityName?cap_first}SearchVo;
import ${voPackagePath}.${entityName?cap_first}Vo;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.stream.Collectors;
import java.util.ArrayList;
@Slf4j
@RestController
public class ${entityName?cap_first}Controller {

    @Autowired
    ${entityName?cap_first}Service ${entityName?uncap_first}Service;
    
    @PostMapping("/${entityName?uncap_first}/add")
    public void insert(@RequestBody ${entityName?cap_first}Vo vo){
        ${entityName?cap_first}Bo ${entityName?uncap_first}Bo = InnerTransferUtil.transferBean(vo, ${entityName?cap_first}Bo.class);
        ${entityName?uncap_first}Service.insert(${entityName?uncap_first}Bo);
    }
    
    @PostMapping("/${entityName?uncap_first}/list")
    List<${entityName?cap_first}Vo> list(@ApiParam("条件查询请求，不分页") @RequestBody ${entityName?cap_first}SearchVo searchVo){
        log.info("查询条件：{}", JSON.toJSONString(searchVo));
        ${entityName?cap_first}SearchBo searchBo = InnerTransferUtil.transferBean(searchVo, ${entityName?cap_first}SearchBo.class);
        List<${entityName?cap_first}Bo> list = ${entityName?uncap_first}Service.list(searchBo);
        if(list == null || list.size() == 0) {
            return new ArrayList<>();
        }
        List<${entityName?cap_first}Vo> voList = list.stream().map(bo -> InnerTransferUtil.transferBean(bo, ${entityName?cap_first}Vo.class)).collect(Collectors.toList()); 
        return voList;
    }


    @PostMapping("/${entityName?uncap_first}/insertBatch")
    void insertBatch(@ApiParam("批量插入接口") @RequestBody List<${entityName?cap_first}Vo> ${entityName?uncap_first}VoList){
        List<${entityName?cap_first}Bo> boList = ${entityName?uncap_first}VoList.stream().map(vo -> InnerTransferUtil.transferBean(vo, ${entityName?cap_first}Bo.class)).collect(Collectors.toList());
        ${entityName?uncap_first}Service.insertBatch(boList);
    }

    @PostMapping("/${entityName?uncap_first}/modify")
        void modify(@ApiParam("修改接口") @RequestBody ${entityName?cap_first}Vo vo){
        ${entityName?cap_first}Bo ${entityName?uncap_first}Bo = InnerTransferUtil.transferBean(vo, ${entityName?cap_first}Bo.class);
        ${entityName?uncap_first}Service.modify(${entityName?uncap_first}Bo);
    }

}